#include <fstream>
#include <iostream>

#include "graph.hpp"

Graph::Graph(std::string &inputFile) {
    graph.clear();
    int err = initial(inputFile);
    if(err == -1) {
        std::cout << "Graph Initial Error" << std::endl;
    }
}

int Graph::initial(std::string &inputFile) {
    std::ifstream inFile(inputFile);
    if(!inFile.is_open()) {
        return -1;
    }
    int nodeNumbers;
    int edgeNumbers;
    int gcRootNumbers;
    inFile >> nodeNumbers >> edgeNumbers >> gcRootNumbers;
    for (int i = 0; i < nodeNumbers; i++) {
        int time;
        inFile >> time;
        Node* node = new Node(i, time);
        graph.push_back(node);
    }
    for (int i = 0; i < gcRootNumbers; i++) {
        int gcRootID;
        inFile >> gcRootID;
        gcRoot.push_back(getNode(gcRootID));
    }
    for (int i = 0; i < edgeNumbers; i++) {
        int from;
        int to;
        inFile >> from >> to;
        Node* fromNode = getNode(from);
        Edge* edge = new Edge(getNode(to), fromNode->firstEdge);
        fromNode->firstEdge = edge;
    }
    return 0;
}